package com.example.clicklistener;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,View.OnLongClickListener {
    private Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button=(Button) findViewById(R.id.button);
        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        Toast.makeText(this, "您点击了按钮", Toast.LENGTH_SHORT).show();
    }

    @Override
    public boolean onLongClick(View view) {
        if(view==button){
            Toast.makeText(this, "您长时间按下了按钮", Toast.LENGTH_SHORT).show();
        }
        return false;
    }
}
